package com.njtoyo.taxi.admin.rest.controller.business.operation_rule;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.DriverFeeRateInfoPresenter;
import com.njtoyo.taxi.admin.rest.presenter.business.operation_rule.DriverServiceArrangementPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverFeeRateCreateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverFeeRateUpdateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.operation_rule.DriverServiceArrangementWrapper;
import com.njtoyo.taxi.admin.service.business.operation_rule.DriverFeeRateService;
import com.njtoyo.taxi.admin.service.business.operation_rule.DriverServiceArrangementService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "司机手续费配置", tags = "司机手续费配置")
@RequestMapping("business/operation-rule/driver-fee-rate")
public class DriverFeeRateController {
    
    @Autowired
    private DriverFeeRateService feeRateService;
    
    @Autowired
    private DriverServiceArrangementService driverServiceService;
    
    @GetMapping("all")
    @ApiOperation(value = "所有手续费信息", notes = "司机手续费配置信息，权限：companies_list")
    @PermissionScope(names = {"companies_list"})
    RestResult<List<DriverFeeRateInfoPresenter>> all(@ModelAttribute("admin") AdminUser adminUser) {
        return feeRateService.all(adminUser);
    }
    
    @GetMapping("")
    @ApiOperation(value = "手续费列表", notes = "司机手续费数据列表，权限：driver_fee_rate")
    @PermissionScope(names = {"driver_fee_rate"})
    RestResult<IPage<DriverServiceArrangementPresenter>> index(@ModelAttribute("admin") AdminUser adminUser, DriverServiceArrangementWrapper wrapper) {
        return driverServiceService.page(adminUser, wrapper);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "手续费详情", notes = "司机手续费数据详情，权限：driver_fee_rate")
    @PermissionScope(names = {"driver_fee_rate"})
    RestResult<DriverServiceArrangementPresenter> detail(@ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id) {
        return driverServiceService.detail(adminUser, id);
    }
    
    @PostMapping()
    @ApiOperation(value = "添加手续费", notes = "新增司机手续费，权限：driver_fee_rate_create")
    @PermissionScope(names = {"driver_fee_rate_create"})
    RestResult create(@ModelAttribute("admin") AdminUser adminUser, @RequestBody @Valid DriverFeeRateCreateWrapper wrapper) {
        return feeRateService.create(adminUser, wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "修改手续费", notes = "修改司机手续费，权限：driver_fee_rate_update")
    @PermissionScope(names = {"driver_fee_rate_update"})
    RestResult update(@ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id, @RequestBody @Valid DriverFeeRateUpdateWrapper wrapper) {
        return feeRateService.update(adminUser, id, wrapper);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除手续费", notes = "删除司机手续费，权限：driver_fee_rate_delete")
    @PermissionScope(names = {"driver_fee_rate_delete"})
    RestResult delete(@ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id) {
        return feeRateService.delete(adminUser, id);
    }

    @DeleteMapping("/cache")
    @ApiOperation(value = "清除缓存", notes = "清除缓存，权限：driver_fee_rate_update,driver_fee_rate_create,driver_fee_rate_delete")
    @PermissionScope(names = {"driver_fee_rate_create", "driver_fee_rate_update", "driver_fee_rate_delete"})
    RestResult deleteCache() {
        return driverServiceService.deleteCache();
    }
}
